package com.atguigu.ssyx.product.service.impl;

import com.atguigu.ssyx.model.product.AttrGroup;
import com.atguigu.ssyx.product.mapper.AttrGroupMapper;
import com.atguigu.ssyx.product.service.AttrGroupService;
import com.atguigu.ssyx.vo.product.AttrGroupQueryVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 杨林
 * @create 2023-07-20 9:31 星期四
 * description:
 */
@Service
public class AttrGroupServiceImpl extends ServiceImpl<AttrGroupMapper, AttrGroup> implements AttrGroupService {
    
    @Autowired
    private AttrGroupMapper attrGroupMapper;

    /**
     * 分页查询平台属性分组列表
     * @param page
     * @param limit
     * @param attrGroupQueryVo
     * @return
     */
    @Override
    public IPage<AttrGroup> getPageList(Long page, Long limit, AttrGroupQueryVo attrGroupQueryVo) {
        //构建分页条件
        Page<AttrGroup> attrGroupPage = new Page<>(page, limit);
        
        //构建查询条件
        LambdaQueryWrapper<AttrGroup> wrapper = new LambdaQueryWrapper<>();
        if (attrGroupQueryVo.getName() != null){
            wrapper.like(AttrGroup::getName,attrGroupQueryVo.getName());
        }
        Page<AttrGroup> pageModel = attrGroupMapper.selectPage(attrGroupPage, wrapper);
        return pageModel;
    }

    /**
     * 查询所有平台属性分组
     * @return
     */
    @Override
    public List<AttrGroup> findAllList() {
        List<AttrGroup> attrGroups = attrGroupMapper.selectList(null);
        return attrGroups;
    }
}
